function exist(board: string[][], word: string): boolean {
    if (!board || board.length === 0 || board[0].length === 0) {
        return false;
    }

    const m = board.length, n = board[0].length;
    const dfs = (i: number, j: number, k: number) => {
        // 下标越界或者不相等
        if (i >= m || i < 0 || j >= n || j < 0 || board[i][j] !== word[k]) {
            return false;
        }

        // 长度一致,找完了
        if (k === word.length - 1) {
            return true;
        }

        // 置空避免重复判断
        board[i][j] = '';
        // 在置空表明已经遍历过该字符了的前提下，继续递归上下右左看是否有满足等于单词的路径，只要有一个路径满足就行，所以 || 连接
        let res = dfs(i - 1, j, k + 1) || dfs(i + 1, j, k + 1) || dfs(i, j + 1, k + 1) || dfs(i, j - 1, k + 1)
        board[i][j] = word[k];
        return res;
    }

    for (let i = 0; i < m; i++) {
        for (let j = 0; j < n; j++) {
            if (dfs(i, j, 0))
                return true;
        }
    }
    return false;
};